//
//  Ball.m
//  lust
//
//  Created by fan on 13-3-26.
//
//

#import "Ball.h"
#import "CCSprite.h"
#import "BallLayer.h"
#define PTM_RATIO 32
@implementation Ball
-(id)init
{
    self=[super init];
    if (self) {
        sprite= [CCSprite spriteWithFile:@"blocks.png"];
        sprite.position=ccp(200, 200);
        b2BodyDef bodyDef;
        bodyDef.position.Set(200/PTM_RATIO, 200/PTM_RATIO);
        bodyDef.type = b2_dynamicBody;
        bodyDef.userData=self;
        b2Body* body=[BallLayer world]->CreateBody(&bodyDef);
        
        b2PolygonShape dynamicBox;
        dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
        
        // Define the dynamic body fixture.
        b2FixtureDef fixtureDef;
        fixtureDef.shape = &dynamicBox;
        fixtureDef.density = 1.0f;
        fixtureDef.friction = 0.3f;
        body->CreateFixture(&fixtureDef);
        body->GetMass();
        [[BallLayer instance]addChild:sprite z:1];
        
    }
    return self;
}

-(void)updatePosition:(b2Vec2)p
{
    sprite.position=ccp(p.x*PTM_RATIO,p.y*PTM_RATIO);
    CCLOG(@"%f,%f",p.x,p.y);
}
@end
